/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef I2c_IRQ_H
#define I2c_IRQ_H

/*******************************************************************************
**                      Include Section                                       **
*******************************************************************************/
#include "Mcal.h"
#include "I2c.h"
#include "I2c_Types.h"

typedef void (*I2c_irq_handle_t)(void);

#define I2C_ISR(I2cHwId) \
ISR(I2c##I2cHwId##_IrqHandler)\
{\
    uint32 coreId = I2c_GetCoreId();\
    /* driver not uesd irq number */\
    I2c_adap_dev_t *arg;\
    for(uint8 I2c_Num = 0U; I2c_Num < I2C_CHN_NUM; I2c_Num++)\
    {\
        if(I2cHwId##U == I2c_Handler[coreId][I2c_Num].adap.hwCh) {\
            arg = &I2c_Handler[coreId][I2c_Num].adap;\
            if(I2c_Handler[coreId][I2c_Num].mdev.msgs[0].polling == I2C_INTR_MOD){\
                (void)sdrv_I2c_master_irq_handler(0U, arg);\
            }\
        }\
    }\
}

ISR(I2c1_IrqHandler);
ISR(I2c2_IrqHandler);
ISR(I2c3_IrqHandler);
ISR(I2c4_IrqHandler);

#endif /* I2c_IRQs_H */

/*******************************************************************************
**                      End of File                                           **
*******************************************************************************/
